package com.example.android.accelerometerplay;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.example.android.common.ActionListener;
import com.example.android.common.MenuControlIF;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class AccelerometerPlayActivity extends Activity {
    
	/**/
	private ListView m_pChild_List_Menu = null;
	private Button m_pChild_Btn_TextTest = null;
	private Button m_pChild_Btn_EditTextTest = null;
	private Button m_pChild_Btn_TouchTest = null;
	private Button m_pChild_Btn_SpeakPhoneTest = null;
	
	////////
	
	
	////////
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // Initialize buttons and list
        InitScreen();
        
        InitListInfo();
    }
    
    private void InitScreen(){
    	// Initialize the buttons and list
//		if (null == m_pChild_Btn_TextTest) {
//			m_pChild_Btn_TextTest = (Button) findViewById(R.id.Btn_TextTest);
//			m_pChild_Btn_TextTest.setOnClickListener(new _Btn_TextText_AL());
//		}
//		
//		if (null == m_pChild_Btn_EditTextTest){
//			m_pChild_Btn_EditTextTest = (Button) findViewById(R.id.Btn_EditTextTest);
//		}
//		
//		if (null == m_pChild_Btn_TouchTest){
//			m_pChild_Btn_TouchTest = (Button) findViewById(R.id.Btn_TouchTest);
//			m_pChild_Btn_TouchTest.setOnClickListener(new _Btn_TouchTest_AL());
//		}
//		
//		if (null == m_pChild_Btn_SpeakPhoneTest) {
//			m_pChild_Btn_SpeakPhoneTest = (Button) findViewById(R.id.Btn_SpeakPhoneTest);
//			m_pChild_Btn_SpeakPhoneTest.setOnClickListener(new _Btn_SpeakPhoneText_AL());
//		}
		
		if (null == m_pChild_List_Menu) {
			m_pChild_List_Menu = (ListView) findViewById(R.id.List_Menu);
			m_pChild_List_Menu.setOnItemClickListener(new _List_Menu_AL());
		}
		
		//////////////////////////////////////////////////////////////////////////////
    }
   
	private void InitListInfo() {
		if (null == m_pChild_List_Menu) {
			return;
		}
		
		SimpleAdapter sa = new SimpleAdapter (this, getData(), R.layout.listitem_1t, new String[] {"info"},new int[] {R.id.listitem_1t_t01});
		m_pChild_List_Menu.setAdapter(sa);
	}
	
	private List<Map<String, Object>> getData(){
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("info", getString(R.string.STR_0001));
		list.add(0, map);
		
		map = new HashMap<String, Object>();
		map.put("info", getString(R.string.STR_0002));
		list.add(1, map);
		
		map = new HashMap<String, Object>();
		map.put("info", getString(R.string.STR_0003));
		list.add(2, map);
		
		map = new HashMap<String, Object>();
		map.put("info", getString(R.string.STR_0004));
		list.add(3, map);
		
		map = new HashMap<String, Object>();
		map.put("info", getString(R.string.STR_0008));
		list.add(4, map);
		
		map = new HashMap<String, Object>();
		map.put("info", getString(R.string.STR_0009));
		list.add(5, map);
		
		return list;
	}
    
    /***
     * 
     * Action listener
     * 
     * */
	
    
    /*-----On Click Listener--------*/
    class _Btn_TextText_AL extends ActionListener.BTN_AL_Base{

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			// Go to text test screen
			MenuControlIF.Forward(AccelerometerPlayActivity.this, TextTestActivity.class);
		}
    }
    
    /*-----On Click Listener--------*/
    class _Btn_TouchTest_AL extends ActionListener.BTN_AL_Base{

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			// Go to text test screen
			MenuControlIF.Forward(AccelerometerPlayActivity.this, TouchTestActivity.class);
		}
    }
    
    /*-----On Click Listener--------*/
    class _Btn_SpeakPhoneText_AL extends ActionListener.BTN_AL_Base{

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			// Go to text test screen
			MenuControlIF.Forward(AccelerometerPlayActivity.this, SpeakPhoneTestActivity.class);
		}
    }
    
    /*-----On Click Listener--------*/
    class _List_Menu_AL extends ActionListener.LIST_AL_Base{
    	@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
    		
			switch (arg2) {
			case 0:
				MenuControlIF.Forward(AccelerometerPlayActivity.this, TextTestActivity.class);
				break;
			case 1:
				break;
			case 2:
				MenuControlIF.Forward(AccelerometerPlayActivity.this, TouchTestActivity.class);
				break;
			case 3:
				MenuControlIF.Forward(AccelerometerPlayActivity.this, SpeakPhoneTestActivity.class);
				break;
			default:
				break;
			}
		}
    }
}